package ar.edu.itba.tp1.tpalan;

import java.util.ArrayList;
import java.util.List;

import ar.edu.itba.tp1.gps.api.GPSProblem;
import ar.edu.itba.tp1.gps.api.GPSRule;
import ar.edu.itba.tp1.gps.api.GPSState;


/**
 * GPSProblem interface.
 */
public class MyGPSProblem implements GPSProblem {

	private List<GPSRule> rules;
	Heuristic heuristic;
	
	public MyGPSProblem(Heuristic heuristic) {
		this.rules = new ArrayList<GPSRule>();
		this.rules.add(new MyGPSRule(Colour.BLUE, 1));
		this.rules.add(new MyGPSRule(Colour.GREEN, 1));
		this.rules.add(new MyGPSRule(Colour.PINK, 1));
		this.rules.add(new MyGPSRule(Colour.RED, 1));
		this.rules.add(new MyGPSRule(Colour.YELLOW, 1));
		this.rules.add(new MyGPSRule(Colour.WHITE, 1));
		this.heuristic=heuristic;
	}
	/**
	 * Provides the initial state for the GPS to start from.
	 * @return The initial state of the problem to be solved.
	 */
	public GPSState getInitState() {
		return new MyGPSState(new FillZoneBoard(Parameters.BOARD_SIZE));
	}
	
	/**
	 * Provides the list of all the rules that the problem involves. 
	 * These rules are state independent.
	 * @return The initial state of the problem to be solved.
	 */	
	public List<GPSRule> getRules() {
		return rules;
	}
	
	/**
	 * Computes the value of the Heuristic for the given state.
	 * @param state The state where the Heuristic should be computed.
	 * @return The value of the Heuristic.
	 */
	public Integer getHValue(GPSState state) {
		Integer hvalue = null;
		switch (this.heuristic){
			case ColorCount: // color count
				hvalue = ((MyGPSState) state).getColourCount()-1;
				break;
			case FarCluster: // remaining colour changes (movements) to the most far cluster from topleft
				hvalue = ((MyGPSState) state).getFarClusterDistance();
				break;
			case Both: // both
				int colourCount = ((MyGPSState) state).getColourCount();
				int farCluster = ((MyGPSState) state).getFarClusterDistance();
				hvalue = Math.max(colourCount, farCluster);
				break;
			case RemainingSquares: // color count
				hvalue = ((MyGPSState) state).getBoardSizeToComplete();
				break;				
			default:
				hvalue = null;
		}
		return hvalue;
	}

	@Override
	public GPSState getGoalState() {
		// TODO Auto-generated method stub
		return null;
	}
}
